package com.zyf.apitest.source;

import com.zyf.apitest.beans.SensorReading;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @author Malegod_xiaofei
 * @create 2021-12-25-20:47
 */
public class SourceTest1_Collection {
    public static void main(String[] args) throws Exception {
        // 创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 设置并行度
        env.setParallelism(1);

        // 从集合中读取数据
        DataStream<SensorReading> dataStream = env.fromCollection((Arrays.asList(
                new SensorReading("sensor_1", 1547718199L, 35.8),
                new SensorReading("sensor_6", 1547718201L, 15.4),
                new SensorReading("sensor_7", 1547718202L, 6.7),
                new SensorReading("sensor_10", 1547718205L, 38.1)
        )));

        DataStreamSource<Integer> integerDataStreamSource = env.fromElements(1, 2, 454, 35, 245, 34, 123, 36, 6, 2346, 23);

        // 打印输出
        dataStream.print("data");
        integerDataStreamSource.print("int");

        // 执行
        env.execute("test");
    }
}
